using System.Collections;

using LocalBoard.Domain;
using LocalBoard.Persistence;

namespace LocalBoard.Controller
{
	[NUnit.Framework.TestFixture]
	public class TestProfileController
	{
		SqlAccessorFactory accessorFactory = new SqlAccessorFactory();
		[NUnit.Framework.SetUp]
		public void setUp()
		{
			_unitUnderTest = new ProfileController(accessorFactory); 
		}
		[NUnit.Framework.TearDown]
		public void tearDown()
		{
			Profile user = accessorFactory.GetProfileAccessor().GetProfileByUserId("userId5");
			if(user != null)
				accessorFactory.GetProfileAccessor().Delete(user.Id);
			_unitUnderTest = null;
		}
		[NUnit.Framework.Test]
		[NUnit.Framework.ExpectedException(typeof(System.Data.SqlClient.SqlException))]
		public void testCreateProfileWithDuplicateId()
		{
			if(accessorFactory.GetProfileAccessor().GetProfileByUserId("userId1") == null)
				accessorFactory.GetProfileAccessor().Insert(new Profile("userId1","userName1","password1","email1"));

			int userId;
			userId = _unitUnderTest.CreateProfile(new Profile("userId1","userName1","password1","email1"));
		}
		[NUnit.Framework.Test]
		public void testCreateProfile()
		{
			Profile user = accessorFactory.GetProfileAccessor().GetProfileByUserId("userId5");
			if(user != null)
				accessorFactory.GetProfileAccessor().Delete(user.Id);
			int userId = _unitUnderTest.CreateProfile(new Profile("userId5","userName5","password5","email5"));
			NUnit.Framework.Assertion.Assert(userId != 0);
		}

		private ProfileController _unitUnderTest;
	}
}
